package com.zwface.demo.function.start;

import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.os.Bundle;

import com.blankj.utilcode.util.ActivityUtils;
import com.blankj.utilcode.util.ColorUtils;
import com.blankj.utilcode.util.StringUtils;
import com.qmuiteam.qmui.util.QMUIStatusBarHelper;
import com.zwface.demo.R;
import com.zwface.demo.function.login.LoginActivity;
import com.zwface.demo.function.main.MainActivity;
import com.zwface.demo.utils.SharedPreferenceUtils;

import androidx.annotation.Nullable;

/**
 * created by 张中文
 * on 2020/2/3
 * 描述：
 */
public class SplashActivity extends Activity {
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //禁止横屏
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
        //沉浸式状态栏
        QMUIStatusBarHelper.translucent(this, ColorUtils.getColor(R.color.transparent));

        setContentView(R.layout.activity_splash);
        init();
    }

    private void init() {
        Thread myThread = new Thread() {//创建子线程
            @Override
            public void run() {
                try {
                    sleep(1000);
                    toActivity();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        };
        myThread.start();//启动线程
    }

    private void toActivity() {
        String userId = SharedPreferenceUtils.getParam(this,SharedPreferenceUtils.USER_ID);
        if(StringUtils.isEmpty(userId)){
            ActivityUtils.startActivity(LoginActivity.class);
        }else{
            ActivityUtils.startActivity(MainActivity.class);
        }
        finish();
    }

}
